From: Timm Bäder Date: Sun, 1 Sep 2019 07:26:16 +0000 (+0200) Subject: icontheme: Inline scan_resources into only caller X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1~1^2~321^2^2~888 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=0b472c23d7002395dfbd99a0371c22bc9bdcf89c;p=gtk4.git icontheme: Inline scan_resources into only caller The previous code was hiding the fact that the scan_resources function almost always did nothing and just used g_resources_enumerate_children() and then returned FALSE, leaving the caller with cleaning up the already allocated IconThemeDir. By inlining this, we make sure that calling code does not even need to allocate the IconThemeDir. --- diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c index 9c095588e3..3dda83c43a 100644 --- a/gtk/gtkicontheme.c +++ b/gtk/gtkicontheme.c @@ -3022,43 +3022,6 @@ scan_directory (GtkIconThemePrivate *icon_theme, return g_hash_table_size (dir->icons) > 0; } -static gboolean -scan_resources (GtkIconThemePrivate *icon_theme, - IconThemeDir *dir, - gchar *full_dir) -{ - gint i; - gchar **children; - - GTK_DISPLAY_NOTE (icon_theme->display, ICONTHEME, - g_message ("scanning resources %s", full_dir)); - - children = g_resources_enumerate_children (full_dir, 0, NULL); - if (!children) - return FALSE; - - dir->icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - - for (i = 0; children[i]; i++) - { - gchar *base_name; - IconSuffix suffix, hash_suffix; - - suffix = suffix_from_name (children[i]); - if (suffix == ICON_SUFFIX_NONE) - continue; - - base_name = strip_suffix (children[i]); - - hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name)); - /* takes ownership of base_name */ - g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix|suffix)); - } - g_strfreev (children); - - return g_hash_table_size (dir->icons) > 0; -} - static void theme_subdir_load (GtkIconTheme *icon_theme, IconTheme *theme, @@ -3185,13 +3148,26 @@ theme_subdir_load (GtkIconTheme *icon_theme, } if (strcmp (theme->name, FALLBACK_ICON_THEME) == 0) - { + { for (d = icon_theme->priv->resource_paths; d; d = d->next) { + int i; + char **children; + /* Force a trailing / here, to avoid extra copies in GResource */ full_dir = g_build_filename ((const gchar *)d->data, subdir, " ", NULL); full_dir[strlen (full_dir) - 1] = '\0'; + + children = g_resources_enumerate_children (full_dir, 0, NULL); + + if (!children) + { + g_free (full_dir); + continue; + } + dir = g_new0 (IconThemeDir, 1); + dir->icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); dir->type = type; dir->is_resource = TRUE; dir->context = context; @@ -3205,7 +3181,24 @@ theme_subdir_load (GtkIconTheme *icon_theme, dir->cache = NULL; dir->subdir_index = -1; - if (scan_resources (icon_theme->priv, dir, full_dir)) + for (i = 0; children[i]; i++) + { + gchar *base_name; + IconSuffix suffix, hash_suffix; + + suffix = suffix_from_name (children[i]); + if (suffix == ICON_SUFFIX_NONE) + continue; + + base_name = strip_suffix (children[i]); + + hash_suffix = GPOINTER_TO_INT (g_hash_table_lookup (dir->icons, base_name)); + /* takes ownership of base_name */ + g_hash_table_replace (dir->icons, base_name, GUINT_TO_POINTER (hash_suffix|suffix)); + } + g_strfreev (children); + + if (g_hash_table_size (dir->icons) > 0) theme->dirs = g_list_prepend (theme->dirs, dir); else theme_dir_destroy (dir);